<?php
require ('../Common/db.php');
$title= trim($_POST['title']);
$tid = $_POST['tid'];
$typename = $_POST['typename'];
$wid=$_POST['wid'];
$intro = $_POST['intro'];
$pic = $_POST['pic'];
$address = $_POST['address'];
//2.上传文件判断类型
$allowtype=array("jpg","jpeg","png","gif","bmp","flv");
$arr=explode(".",$_FILES["pic"]["name"]);
$suffix=$arr[count($arr)-1];
if(! in_array($suffix,$allowtype)){
    echo "文件类型错误！";
    exit;
}else{
    echo"<br>封面已上传<br>";
}
//3.拷贝文件
$filepath="../../images/blog/";
$randname=date("YmdHis").rand(100,999).".".$suffix;
move_uploaded_file($_FILES["pic"]["tmp_name"],$filepath.$randname);
//插入数据库
$sql="insert into blogs values (0,'$title','$tid','$wid','$intro','沐歌丨丶',0,NOW(),'0','0','$address','$randname',0)";
echo $sql.'<br/>';
//执行SQL语句
$result = mysql_query($sql) or die('插入失败！'.mysql_error());
//判断是否插入成功
$num = mysql_affected_rows();
if($num!=1){
    echo "添加失败,2秒后返回博客列表页";
    header("refresh:2;url='blogList.php'");
} else {
    header("location:blogList.php");
}
//关闭数据库
mysql_close();
?>